package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            Statement sta = connection.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor\n" +
                    "FROM teacher t \n" +
                    "JOIN class c ON t.id=c.teacher_id\n" +
                    "WHERE t.title='一级讲师'";
            ResultSet rs = sta.executeQuery(sql);
            while(rs.next()){
                String tName = rs.getString("t.name");
                String gender = rs.getString("t.gender");
                String cName = rs.getString("c.name");
                int floor = rs.getInt("c.floor");
                System.out.println(tName + " " + gender + " " + cName + " " + floor );
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
